package com.hz.ruoyiequipment.data.mapper;

import com.hz.ruoyiequipment.data.domain.AgrEquipmentTr;
import com.hz.ruoyiequipment.data.domain.vo.SoilEquipment;
import com.hz.ruoyiequipment.data.domain.vo.SoilTimeData;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: xqd
 * @CreateDate: 2025/03/07/16:09
 * @Description: 土壤墒情设备表接口
 */
public interface AgrEquipmentTrMapper {
    /**
     * @param agrEquipmentTr 土壤墒情设备实体类
     * @return: 改变行数（大于0，新增成功）
     * @Author: xqd
     * @Date: 2025/3/8 10:04
     * @Description: 新增设备到土壤墒情设备表
     */
    @Insert("INSERT INTO agr_equipment_tr (equipment_id, tr_diameter, tr_length, tr_material, tr_interface, tr_storage, tr_time, tr_protection,create_time) " +
            "VALUES (#{equipmentId}, #{trDiameter}, #{trLength}, #{trMaterial}, #{trInterface}, #{trStorage}, #{trTime}, #{trProtection},#{createTime})")
    Integer insertAgrEquipmentTr(AgrEquipmentTr agrEquipmentTr);

    /**
     * @param equipmentId 设备ID
     * @return:
     * @Author: xqd
     * @Date: 2025/3/8 16:51
     * @Description: 查看设备是否绑定地块
     */
    @Select("SELECT equipment_id FROM agr_equipment_plots WHERE equipment_id = #{equipmentId}")
    Integer getEquipmentId(Long equipmentId);

    /**
     * @param soilEquipment SoilEquipment实体类
     * @return:
     * @Author: xqd
     * @Date: 2025/3/8 16:52
     * @Description: 修改土壤墒情设备表中的数据
     */
    Integer updateAgrEquipmentTr(SoilEquipment soilEquipment);

    /**
     * @param soilEquipment SoilEquipment实体类
     * @return:
     * @Author: xqd
     * @Date: 2025/3/8 16:53
     * @Description: 修改设备地块表中设备绑定的地块
     */
    Integer updateAgrEquipmentPlot(SoilEquipment soilEquipment);

    /**
     * @return:
     * @Author: xqd
     * @Date: 2025/3/8 16:54
     * @Description: 将设备绑定的地块信息插入到设备地块表中
     */
    Integer insertAgrEquipmentPlot(SoilEquipment soilEquipment);

    /**
     * @return:
     * @Author: xqd
     * @Date: 2025/3/8 16:55
     * @Description: 删除土壤墒情设备表中的数据
     */
    @Delete("DELETE FROM agr_equipment_tr WHERE equipment_id = #{equipmentId}")
    void delAgrEquipmentTrByEquipmentId(Long equipmentId);

    /**
     * @return:
     * @Author: xqd
     * @Date: 2025/3/8 16:55
     * @Description: 删除设备地块表中设备绑定的地块
     */
    @Delete("DELETE FROM agr_equipment_plots WHERE equipment_id = #{equipmentId}")
    void delAgrEquipmentPlotByEquipmentId(Long equipmentId);


    SoilTimeData getSoilTimeData(Long equipmentId);


    // 查询设备历史数据
    List<SoilTimeData> getSoilTimeDatas(Long equipmentId);

    // 查询设备信息头部
    SoilEquipment getSoilTimeDataHead(Long equipmentId);



    //增加土壤墒情机历史数据
    @Insert("INSERT INTO agr_soil_data (equipment_id, record_date, soil_moisture, soil_temperature, soil_salinity, soil_ph) " +
            "VALUES (#{equipmentId}, #{recordDate}, #{soilMoisture}, #{soilTemperature}, #{soilSalinity}, #{soilPh})")
    int insertSoilTimeData(SoilTimeData soilTimeData);



}
